/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package _2012;
import com.sun.org.apache.bcel.internal.generic.GOTO;
import java.net.*;
import java.io.*;
/**
 *
 * @author nisarg
 */
public class problem_E {
    static int no = 5;
    static int[] result = new int[no];
    static int arr[][] = {{0,1,0,0,0,},{0,0,0,1,1},{1,1,0,0,1},{1,0,1,0,1},{1,0,0,1,0}};
    static int arr1[][] = new int[no][no];
    static int arr2[][] = new int[no][no];
    static int index = 0;
    static int error = 0;
    static int oned[] = new int[no];
    static int index_store[] = new int[no];
    public static void main(String args[]) {
        for(int i=0;i<no;i++) {
            result[i] = -1;
        }
        /*try {
            for(int i=0;i<no;i++) {
                for(int j=0;j<no;j++) {
                    BufferedReader kb = new BufferedReader(new InputStreamReader(System.in));
                    arr[i][j] =Integer.parseInt(kb.readLine());
                }
            }
        }
        catch(Exception e) {
            error = 1;
        }*/
        
        
        /* ACTUAL CODING START FROM HERE.........*/
        for(int i=0;i<no;i++) {
            int k=0;
            arr1[i][i] = i;
            for(int j=0;j<no;j++) {
                if(arr[i][j] == 1) { /* arr1[][] is used as pegion hole... */
                    if(i!=j)
                    arr1[i][j] = j;
                    System.out.print("1 ");
                }
                else if(i!=j) {
                    arr1[i][j]=-1;
                    System.out.print("0 ");
                }
            }
            System.out.println();
        }
        System.out.println();
        System.out.println();
        System.out.println();
        System.out.print("Control stack : binary_addition has to be performed here");
        for(int i=0;i<no;i++) { /* PRINTS THE OUTPUT IN BINARY*/
            for(int j=0;j<no;j++) {
                if(arr1[i][j] != -1)    {
                    //System.out.print("1 ");
                    arr1[i][j] = 1;
                }//System.out.print(arr1[i][j] + " ");
                else {
                    //System.out.print("0 ");
                    arr1[i][j] = 0;
                }
            }
            System.out.println("");
        }
        sort();
        
        for(int i=0;i<no;i++) index_store[i] = 0;
        for(int i=0;i<no;i++) { /*  A LOOP TO STORE THE 1's indexes   */
            if(arr1[no-1][i]==0) index_store[i] = 1;
        }
        
        
        for(int i=0;i<no;i++) { /* PRINTS THE OUTPUT IN BINARY*/
            for(int j=0;j<no;j++) {
                    System.out.print(arr1[i][j] + " ");
            }
            System.out.println("");
        }
        System.out.println("INDEX");
        for(int i=0;i<no;i++) {
            System.out.print(index_store[i] + " ");
        }
        for(int i=0;i<no;i++) {
            
        }
    }
        
    //}
    static int sort() { /* TO SORT THE arr1[][] according to the number of 1's in the row...*/
        //int i=0;
        int total = 0;
        
        for(int i=0;i<no;i++) {
            for(int j=0;j<no;j++) {
                if(arr1[i][j]==1) {
                    total++;
                }
            }
            oned[i] = total;
            total = 0;
        }
        int temp = 0;
        for(int i=0;i<no;i++) {
            for(int j=0;j<no;j++) {
                if(oned[i]<oned[j]) {
                    temp = oned[i];
                    oned[i] = oned[j];
                    oned[j] = temp;
                    swap(i,j);
                }
            }
        }
        return 0;
    }
    static void swap(int i,int j) { /*  TO SWAP THE ROWS OF ARRAY : arr1[][]   */
        int temp = 0;
        for(int i1=0;i1<no;i1++) {
            temp = arr1[i][i1];
            arr1[i][i1] = arr1[j][i1];
            arr1[j][i1] = temp;
        }
    }
}


/*int total = 0;
        for(int i=0;i<no;i++) {
            for(int j=0;j<no;j++) {
                total += arr1[i][j]*(2^(no-1));
            }
            oned[i] = total;
            total = 0;
        }*/
        
        
        
        
        
        /*int ind = 0;
        while(isZero(result)==0 && ind<no) {
           anding(ind++);
        }
        if(isZero(result)==1 && error!=1) {
            System.out.println("Done : " + ind);
        }
        else if(error==1) System.out.println("Incorrect input...");
        else
            System.out.println("Not Done");*/


/*static void anding(int index) {
        int i=0;
        while(i<no) {
            result[i] = result[i] | arr1[index][i];
            i++;
        }
    }
    static int isZero(int[] a) {
        int i=0,flag=1;
        while(i<no) {
            if(a[i++]==0) flag=0;
        }
        return flag;
    }
    static int bin_to_int(int a) {
        //int i=0;
        int total = 0;
        
        for(int i=0;i<no;i++) {
            for(int j=0;j<no;j++) {
                total += arr1[i][j]*(2^(no-1));
            }
            oned[i] = total;
            total = 0;
        }
        return 0;
    }*/